package com.webcash.CNBoard.Controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.webcash.CNBoard.Model.Employee;
import com.webcash.CNBoard.Model.Login;
import com.webcash.CNBoard.Model.Team;
import com.webcash.CNBoard.Service.EmployeeService;



@Controller
@RequestMapping("/team")
@SessionAttributes("login")
public class DepartmentTeamListController {
	@Autowired
	EmployeeService employeeService;
	
	@RequestMapping
	public String action(@ModelAttribute Login login, Model model){
		
		Employee emp = employeeService.getEmployeeById(login.getId());
		Team team = employeeService.getMyTeamInfoByTeamNoAndDeptNo(emp.getTeamNo(), emp.getDeptNo());
		List<Employee> teamMember = employeeService.getTeamMemberListbydeptNoAndTeamNo(emp);
		List<Employee> staff = new ArrayList<Employee>();				//사원
		List<Employee> supervisor = new ArrayList<Employee>();			//주임
		List<Employee> assistantManger= new ArrayList<Employee>();		//대리
		List<Employee> deputyManager = new ArrayList<Employee>();		//과장
		List<Employee> Manager = new ArrayList<Employee>();				//부장
		for(int i=0;i<teamMember.size();i++){
			switch(Integer.parseInt(teamMember.get(i).getPosition())){
			case 1:
				staff.add(teamMember.get(i));
				break;
			case 2:
				supervisor.add(teamMember.get(i));
				break;
			case 3:
				assistantManger.add(teamMember.get(i));
				break;
			case 4:
				deputyManager.add(teamMember.get(i));
				break;
			case 5:
				Manager.add(teamMember.get(i));
				break;
			}
			
		}
		model.addAttribute("emp", emp);
		model.addAttribute("staff", staff);
		model.addAttribute("supervisor", supervisor);
		model.addAttribute("assistantmanager", assistantManger);
		model.addAttribute("deputymanager", deputyManager);
		model.addAttribute("manager", Manager);
		model.addAttribute("team", team);
		
		return "myteam/teamPage";
	}
	

	
}
